<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="../js/axios.min.js" type="text/javascript"></script>
    <script src="../js/vue.js" type="text/javascript"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <title>我的预约</title>
</head>
<body>
<div id="app">
    <el-container>
        <el-main>
            <!--条件查询-->
            <el-form :inline="true" class="demo-form-inline">
                <el-form-item label="查询">
                    <el-input v-model="findForm.key" placeholder="关键字"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="search()">查询</el-button>
                </el-form-item>
            </el-form>
            <!--展示我的预约单-->
            <el-table :data="book" border>
                <el-table-column prop="no" label="预约号">
                </el-table-column>
                <el-table-column prop="coachName" label="教练">
                </el-table-column>
                <el-table-column prop="createTime" label="创建时间">
                </el-table-column>
                <el-table-column prop="lessonName" label="课程">
                </el-table-column>
                <el-table-column prop="lessonTime" label="上课时间">
                </el-table-column>
                <el-table-column prop="state" label="状态">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button v-if="scope.row.state=='待处理'" type="text" size="small" @click="del(scope.row)">取 消</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!--分页-->
            <div class="block">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="pageInfo.currentPage"
                        :page-sizes="[3, 4]"
                        :page-size="100"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="pageInfo.total">
                </el-pagination>
            </div>
        </el-main>
    </el-container>
</div>
<script>
    new Vue({
        el: "#app",
        data() {
            return {
                pageInfo: {
                    currentPage: 1,// 当前页
                    size: 3,// 每页多少条
                    total: 1// 总条目数
                },
                book: [],
                findForm:{
                    key: "",
                    size: 3,
                    page: 1
                }
            }
        },
        methods: {
            // 分页 - 更改每页条数
            handleSizeChange(val) {
                this.pageInfo.size = val
                this.getAll();
            },
            // 分页 - 更改当前页
            handleCurrentChange(val) {
                this.pageInfo.currentPage = val
                this.getAll();
            },
            // 获取所有
            getAll(){
                axios.get("/book/getMyBook?page="+this.pageInfo.currentPage+"&size="+this.pageInfo.size).then(resp=>{
                    if(resp.status === resp.data.code){
                        this.book = resp.data.data.records
                        this.pageInfo.total = resp.data.data.total
                        console.log(this.book)
                    }
                })
            },
            // 条件查询
            search(){
                axios.get("/book/search",{params:this.findForm}).then(resp=>{
                    if(resp.status === resp.data.code){
                        this.book = resp.data.data.records
                        this.pageInfo.total = resp.data.data.total
                    }
                })
            },
            // 取消预约
            del(row){
                axios.delete("/book/del?bookId="+row.bookId).then(resp=>{
                    if(resp.status === resp.data.code){
                        this.$message({
                            type: 'success',
                            message: '取消成功'
                        });
                        this.getAll()
                    }
                })
            }
        },
        created() {
            this.getAll()
        }
    })
</script>
</body>
</html>